package sparkExamples.exerciseDemo

import org.apache.spark.{SparkConf, SparkContext}

object ExerciseDemo08 {

  def main(args: Array[String]): Unit = {

    val conf = new SparkConf().setAppName("ExerciseDemo").setMaster("local[*]")
    val sparkContext = new SparkContext(conf)

    val txtRDD = sparkContext.textFile("src\\main\\scala\\data\\exerciseData.txt")
    txtRDD.cache()

    /**
     * 17、全校语文成绩最高分是多少？
     */
    val maxChinses: Int = txtRDD.filter {
      line => {
        val data = line.split(" ")
        if (data(4) == "chinese") true else false
      }
    }.map {
      line => {
        val data = line.split(" ")
        data(5).toInt
      }
    }.collect().max

    println("校语文成绩最高分:" + maxChinses)

    sparkContext.stop()
  }

}
